﻿Imports System.Data.SqlClient

Public Class clsAdeudosTradicionales
    Private mintidAdeudo As Integer
    Private mintidcuenta As Integer
    Private mstrCodigo As String
    Private mstrNombre As String
    Private mstrTipo As String

    Public Property idAdeudo() As Integer
        Get
            Return mintidAdeudo
        End Get
        Set(ByVal value As Integer)
            mintidAdeudo = value
        End Set
    End Property
    Public Property idcuenta() As Integer
        Get
            Return mintidcuenta
        End Get
        Set(ByVal value As Integer)
            mintidcuenta = value
        End Set
    End Property
    Public Property codigo() As String
        Get
            Return mstrCodigo
        End Get
        Set(ByVal value As String)
            mstrCodigo = value
        End Set
    End Property
    Public Property nombre() As String
        Get
            Return mstrNombre
        End Get
        Set(ByVal value As String)
            mstrNombre = value
        End Set
    End Property
    Public Property Tipo() As String
        Get
            Return mstrTipo
        End Get
        Set(ByVal value As String)
            mstrTipo = value
        End Set
    End Property
    Public Sub New()
        mintidAdeudo = 0
        mintidcuenta = 0
        mstrCodigo = ""
        mstrNombre = ""
        mstrTipo = ""

    End Sub
    Public Sub Insertar()
        Dim sql As String = "Insert Into AdeudosTradicionales (" & _
                            "IdCuenta," & _
                            "Codigo," & _
                            "Nombre," & _
                            "Tipo)" & _
                            "VALUES (" & _
                            "@IdCuenta," & _
                            "@Codigo," & _
                            "@Nombre," & _
                            "@Tipo)"

        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim Command As New SqlCommand(sql, cnConn)

        Command.Parameters.AddWithValue("IdCuenta", mintidcuenta)
        Command.Parameters.AddWithValue("Codigo", mstrCodigo)
        Command.Parameters.AddWithValue("Nombre", mstrNombre)
        Command.Parameters.AddWithValue("Tipo", mstrTipo)
       


        cnConn.Open()
        Dim RowsAffected As Integer = Command.ExecuteNonQuery

        If RowsAffected > 0 Then
            cnConn.Close()
        Else
            MsgBox("No fue posible insertar el registro ", MsgBoxStyle.Exclamation, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End If
    End Sub
   End Class
